import java.awt.event.KeyEvent;

import org.powerbot.core.script.job.Task;
import org.powerbot.core.script.job.state.Node;
import org.powerbot.game.api.methods.Settings;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.node.GroundItems;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.interactive.Player;


public class EOC extends Node{

	@Override
	public boolean activate() {
		return  Players.getLocal() != null 
				&& Players.getLocal().isInCombat();
	}

	
	@Override
	public void execute() {
		Player p = Players.getLocal();
		if(!Widgets.get(640).getChild(1).visible())
		{
			Mouse.click(Random.nextInt(501, 512), Random.nextInt(380, 385), true);
			
			Task.sleep(300);
		}
		if( !Widgets.get(137).getChild(56).getText().equals("[Press Enter to Chat]") )
		{
			Keyboard.sendKey((char)KeyEvent.VK_ESCAPE);
			Keyboard.sendKey((char)KeyEvent.VK_ESCAPE);
			if(Random.nextInt(0, 100)>50)
			{
				Keyboard.sendKey((char)KeyEvent.VK_ESCAPE);
			}
		}
		if(FireGiant.timers.get(0).Ready())
		{
			if(FireGiant.timers.get(4).Ready() && Settings.get(679) == 1000 && FireGiant.getHpPercent() < 70)
			{
				/*switch(FireGiant.timers.get(4).step)
				{
				case 0:
					Keyboard.sendKey('5');
					System.out.println("step1");
					FireGiant.timers.get(4).step = 1;
					break;
				case 1:
					Keyboard.sendKey('4');
					System.out.println("step2");
					FireGiant.timers.get(4).step = 2;
					break;
				case 2:
					Keyboard.sendKey('6');
					System.out.println("step3");
					FireGiant.timers.get(4).step = 0;
					
					break;
				default:
					
					break;
				}*/
				Keyboard.sendKey('4');
				FireGiant.timers.get(4).Reset();
				FireGiant.timers.get(0).Reset();
			}
			else if (p.isInCombat())
			{
				//find next target here if one isnt set, then once we start attacking that one replace the main one with that one.
				//if(FireGiant.nextNpc==null)
					
				if(FireGiant.timers.get(3).Ready() && Settings.get(679) == 1000 && FireGiant.getHpPercent() > 80 )
				{
					Keyboard.sendKey('3');
					FireGiant.timers.get(0).Reset();
					FireGiant.timers.get(3).Reset();
				}
				else if(FireGiant.timers.get(2).Ready())
				{				
					Keyboard.sendKey('2');
					FireGiant.timers.get(0).Reset();
					FireGiant.timers.get(2).Reset();
				}
				else if(FireGiant.timers.get(1).Ready())
				{
					Keyboard.sendKey('1');
					FireGiant.timers.get(0).Reset();
					FireGiant.timers.get(1).Reset();
				}
			}
		}
	}
}
